package day19.HomeWork;

public class Climber extends Thread {
    private Integer speed;
    private Integer height;
    private String name;

    public Climber() {
    }

    public Climber(Integer speed, String name) {
        this.name = name;
        this.speed = speed;
        this.height = 0;
    }

    public void clib() {
        while (height < 1000) {
            synchronized (this) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                height = height + speed;
                if (height % 100 == 0) {
                    System.out.println(this.getName() + "爬了" + height + "米,花费时间"+(height/speed));
                }
            }
        }
    }

    @Override
    public void run() {
        clib();
    }

    public Integer getSpeed() {
        return speed;
    }

    /**
     * 设置
     *
     * @param speed
     */
    public void setSpeed(Integer speed) {
        this.speed = speed;
    }

    public String toString() {
        return "Climber{speed = " + speed + ", height = " + height + "}";
    }
}

class ClimberTest {
    public static void main(String[] args) throws InterruptedException {
//        Climber c = new Climber(50, "一");
//        Climber c2 = new Climber(25, "二");
//        Climber c3 = new Climber(50, "三");
//        Thread t1 = new Thread(c, "一号");
//        Thread t2 = new Thread(c2, "二号");
//        Thread t3 = new Thread(c3, "三号");
        Climber t1=new Climber(50,"一");
        Climber t2=new Climber(100,"二");
        Climber t3=new Climber(200,"三");
        t1.start();
//        Thread.sleep(1000);
        t2.start();
//        Thread.sleep(1000);
        t3.start();
    }
}